package com.example.servicewallet.controller;


import com.example.servicewallet.entity.TUser;
import com.example.servicewallet.service.TUserService;
import com.example.servicewallet.utils.R;
import com.example.servicewallet.vo.LoginVo;
import com.example.servicewallet.vo.RegisterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2023-02-08
 */
@RestController
@RequestMapping("/servicewallet/tuser")
@Api(description = "用户钱包用户模块")
public class TUserController {

    @Autowired
    private TUserService userService;

    /**
     * 注册
     * @param registerVo
     * @return
     */
    @ApiOperation(value = "注册用户")
    @PostMapping("register")
    public R registerUser(@RequestBody RegisterVo registerVo) {
        userService.register(registerVo);
        return R.ok();
    }

    /**
     * 登录
     * @param user
     * @return
     */
    @ApiOperation(value = "登录用户")
    @PostMapping("login")
    public R loginUser(@RequestBody LoginVo user) {
        String token = userService.login(user);
        return R.ok().data("token", token);
    }
}

